import React from 'react';
import Notification from 'rc-notification';

/*
 消息弹出组件简单封装
 ======================================================== */
let Notify = (function(){
    let notifyKey = "mcmurphy-notify";

    let notifyInstance = null;

    let removeNotify = function(){
        notifyInstance.removeNotice(notifyKey);
    };

    let makeNotify = function(text, duration = 3){
      
      //km：先销毁已存在的实例
      if (notifyInstance !== null) {
        notifyInstance.destroy();
      }

      notifyInstance = Notification.newInstance({
          key : notifyKey, 
          style: {
            'bottom': 30,
            'left': '50%'
          }
      });
      
      notifyInstance.notice({
        content: text,
        duration: duration,
        onClose : function(){
          removeNotify();
        }
      });
    };

    return {
       makeNotify : makeNotify,
       removeNotify : removeNotify
    };
})();

module.exports = Notify;
